package blend

import "math"

func BlendChar(charA [][]float64, charB [][]float64, length, width int) (res [][]float64) {
	res = make([][]float64, width)
	for i := 0; i < width; i++ {
		temp := make([]float64, length)
		for j := 0; j < length; j++ {
			//重叠区域
			if isChar(charA[i][j]) && isChar(charB[i][j]) {
				temp[j] = 1
				//非重叠区域
			} else if !isChar(charA[i][j]) && !isChar(charB[i][j]) {
				temp[j] = 0
			} else {
				total := math.Abs(charB[i][j]) + math.Abs(charA[i][j])
				//只在B	[0.5,0.9]
				if isChar(charB[i][j]) {
					temp[j] = 0.9 - math.Abs(charB[i][j])/total*0.4
				} else {
					//只在A	[0.1,0.5]
					temp[j] = 0.5 - math.Abs(charA[i][j])/total*0.4
				}
			}
		}
		res[i] = temp
	}
	return
}

func isChar(n float64) bool {
	return n <= 0
}
